Method and apparatus for programming software components

ABSTRACT

A method and apparatus are disclosed for programming software components that treats software components as the basic unit of abstraction and computation. A software component is encapsulated and classes and other program entities, such as data fields and methods, within a given component do not exist beyond a component boundary. A component interacts with other components only by means of a defined set of input and output ports. A component can inherit and implement ports declared in a template and can declare and implement new ports. A component can only access the external environment through its output ports. An output port of one component can only be connected to a conforming input port of another component. A connect statement is an explicit plumbing operation for connecting components together. Interactions between components are loosely coupled. A related set of templates can be grouped together to form a group. Groups are useful for implementing implicit invocation and multicasting.

CROSS REFERENCE TO RELATED APPLICATIONS

This application claims the benefit of U.S. Provisional Application No.60/276,237, filed Mar. 15, 2001.

FIELD OF THE INVENTION

The present invention relates generally to the fields of softwareprogramming and, more particularly, to methods and apparatus forprogramming software components.

BACKGROUND OF THE INVENTION

The cost and complexity of developing large-scale software systems hasincreased dramatically in recent years. Software reuse and softwaremaintenance are two of the biggest challenges in software engineering.Software reusability is a performance metric indicating the degree towhich a software module or other software product can be used in morethan one computer program or system. Software maintenance includes anymodifications to a software product after the product is initiallydelivered, e.g., to correct faults, improve performance or to adapt theproduct to another environment.

Object-oriented (OO) software development techniques have been said tooffer significant advantages in the context of software reuse andmaintenance. Generally, object-oriented techniques represent real-worldand abstract objects using programmed objects. The concept ofabstraction allows object-oriented programmers to focus only on relevantcharacteristics of the real-world domain. While object-orientedprogramming techniques have offered significant advances in the area ofsoftware reuse and maintenance, such object.-oriented techniques sufferfrom a number of limitations, which if overcome, could greatly improvethe ability to reuse and maintain software products.

Most current component technologies are based on a set of standards,such as Component Object Model (COM), Enterprise JavaBeans (EJB), andCommon Object Request Broker Architecture (CORBA). For a more detaileddiscussion of the current state of component software technology, see,for example, Clemens Szyperski. Component Software: BeyondObject-Oriented Programming. Addison-Wesley, 1999, incorporated byreference herein.

Generally, these component models define a set of interfaces or servicesthat can be invoked by clients. Existing component models have strivedto ensure that components are reusable modules that can be inserted intoany compatible system, without knowing the internal details of thecomponent. For example, a component that is developed using the WebSpereplatform from International Business Machines Corporation of Armonk,N.Y. should seamlessly be portable to a WebLogic platform. In practice,however, this generally does not happen since components are artifactsof Application Programming Interfaces (APIs), and there is no clearsemantic definition of a component. Currently, very little research hasbeen done in promoting components as first-class citizens in a mainstream programming language.

A need therefore exists for a method for programming software componentsthat enhances the maintainability and reusability of components.

SUMMARY OF THE INVENTION

Generally, a method and apparatus are disclosed for programming softwarecomponents that treat software components as the basic unit ofabstraction and computation. Thus, a software component is encapsulatedand classes and other program entities, such as data fields and methods,within a given component do not exist beyond a component boundary. Onecomponent cannot inherit another component's internal structure andbehavior.

A component interacts with other components only by means of a definedset of input and output ports. A component can inherit and implementports declared in a template and can declare and implement new ports. Acomponent must attach each of its input ports to a concrete class withinit. Thus, when a message arrives at an input port of a component, themessages should be processed by some logic (i.e., classes) in thecomponent.

A component can only access the external environment through its outputports. Thus, a component can only invoke services of other componentsvia its own output ports. An output port of one component can only beconnected to a conforming input port of another component. Port typingrestricts the kinds of messages (i.e., operations) that can be passedfrom one component to another component. A connect statement is anexplicit plumbing operation for connecting components together. Theconnect statement creates dependencies among components and ensures thatthe corresponding types and protocols of each connected component match.

According to a further feature of the invention, interactions betweencomponents are loosely coupled. A looser coupling between componentshelps improve reusability and maintenance of components. Generally, onecomponent is not aware of the identity of other components in a system.Among other benefits, loose coupling enhances maintainability andreusability of components. Implicit invocation is an architectural stylefor achieving such loose coupling among components. A related set oftemplates can be grouped together to form a group. Groups are useful forimplementing implicit invocation and multicasting.

A more complete understanding of the present invention, as well asfurther features and advantages of the present invention, will beobtained by reference to the following detailed description anddrawings.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 illustrates the structure of two exemplary components inaccordance with the present invention;

FIG. 2 is a block diagram showing the architecture of an illustrativesoftware component programming system incorporating features of thepresent invention;

FIG. 3 defines the syntax used by the present invention; and

FIG. 4 outlines the identifies used by the present invention.

DETAILED DESCRIPTION OF PREFERRED EMBODIMENTS

According to one aspect of the present invention, a software programmingenvironment is disclosed for programming software components. In thesoftware programming environment of the present invention, softwarecomponents are first-class citizens that have precisely defined sets ofinput and output typed ports. FIG. 1 illustrates the structure of twoexemplary components 110-1, 110-2 (collectively, referred to ascomponents 110) in accordance with the present invention. According toanother aspect of the present invention, a component 110 is the basicunit of abstraction and computation. Thus, classes and other programentities within a given component 110 do not exist beyond a componentboundary.

As shown in FIG. 1, a component 110 has a number of input ports 112-1through 112-N (collectively, input ports 112) and a number of outputports 114-1 through 114-N (collectively, output ports 114). A component110 interacts or communicates with another component, such as thecomponent 110-2, only via these ports 112, 114. Thus, these ports 112,114 are interfaces or plumbing mechanisms that connect components 110together.

A component 110 is required to specify certain external contracts sothat other components 110 can connect to it. Contracts of a component110 may consist of both input contracts and output contracts. One shouldbe able to specify these contracts at an abstract level without worryingabout the implementation details. The software programming environmentof the present invention provides a template to specify a part of theabstract contract of a component 110. As discussed further below in asection entitled “Defining and Creating Components,” template consistsof declarations for input ports and output ports. A port in a templateconsists of three parts: (1) a keyword indicating the direction of theport (either in or out); (2) a type, such as Bool, indicating the typeof the port; and (3) a name for the port, such as xin. The type of theport can only be of interface types (since we use interface to plumbcomponents together).

A component 110 in the software programming environment of the presentinvention implements the abstract “contract” defined by a template. Asshown in FIG. 1, a component 110 in the present software programmingenvironment consists of two portions: (1) an external portion that othercomponents 110 can see, and (2) an internal portion that is private tothe component 110. Thus, a client cannot access the implementation of acomponent 110 directly, but only through the input ports 112 of thecomponent 110.

A component 110 can inherit and implement ports declared in a template(additionally, a component 110 itself can declare and implement newports). The internal portion of a component 110 is made of a set of datafields, methods, and classes. When messages (i.e., interface operations)arrive at an input port of a component 110, the messages should beprocessed (i.e, implemented) by some logic (i.e., classes) in thecomponent 110.

A component 110 must attach each of its input ports 112-i to a concreteclass within it. This class acts as a proxy to the messages that arriveat the input port 112. The proxy class should be able to handle alloperations that arrive at the input port 112 (i.e., implement theinterface of the input port 112). A connect statement is an explicitplumbing operation for connecting components together. The connectstatement creates dependencies among components and ensures that thecorresponding types and protocols of each connected component 110 match.A component can only invoke services of other components via its ownoutput ports. This feature allows a looser coupling between components.Looser coupling helps improve reusability and maintenance of components.Thus, a component 110 can only access the environment through its outputports 114.

The basic properties of software components 110 are discussed furtherbelow in a section entitled “Basic Properties of Software Components.”

ILLUSTRATIVE EXAMPLE

Consider a simple example where a client wants to interact with aboolean component that implements standard Boolean operations (such asnot and nand). The first step is to define an interface (i.e., the setof operations) that the Boolean component is expected to provide. Thefollowing code segment defines an interface Bool that defines twostandard operations (not and nand) on the primitive boolean type.

interface Bool { boolean not(boolean x); boolean nand (boolean x,boolean y); }

The following code segment is a template for a boolean component 110that consists of only one input port 112. In general, a template mayconsist of multiple input ports and multiple output ports.

template BooleanTempl { in Bool xin;//input port }

The following code segment defines a component 110, referred to asBooleanComp, implementing the template, BooleanTempl, defined above:

component BooleanComp implements BooleanTempl { attach xinBoolClass;//attach input port xin to class BoolClass; BooleanComp( ){...}//constructors. class BoolClass implements Bool { booleannot(boolean x) {...}; boolean nand (boolean x, boolean y) {...} } }

Thus, the input port xin is “attached” to the class BoolClass. Thiscompletes our implementation of BooleanComp components. Thus, the classBoolClass should be able to handle all operations that arrive at theinput port xin.

The following code segment creates a client that uses the booleancomponent:

component ClientC { out Bool xout;//output port ClientC( ){...};//component constructor static void main( ) { boolean c = true;BooleanComp BC = new BooleanComp( );//create a component instanceClientC CC = new ClientC( )// connect CC.xout to BC.xin;//connect thetwo components boolean c1 = CC.xout.not(c);//get your work done booleanc2 = CC.xout.nand(c,c1); disconnect CC.xout;//finally disconnect. } }

The client component ClientC has one output port 114. The main( ) methodcan only be called by the virtual machine (VM) or the runtime system,and is the entry point to the application. In ClientC, an instance ofClientC and BooleanComp components are created. Next, the output portCC.xout of the ClientC instance is connected to the input port BC.xin ofthe BooleanComp instance. The connect statement is an explicit plumbingoperation for connecting components together. Once the connection isestablished, the services of BooleanComp component can be used.

As previously indicated, a component 110 can only invoke services ofother components 110 via its own output ports 114. In the presentexample, it is important to remember that the not( ) service isavailable at the output port 114 only if the output port 114 waspreviously connected to a component 110 that provides the not service.

Basic Properties of Software Components

A component 110 in accordance with the present invention is a pluggableunit. Generally, a component 110 is comprised of a collection ofclasses. A key concept in building a software system from off-the-shelfsoftware components is the notion of abstraction. To use a component110, a programmer should know what it is expected to do when assembledas part of a system. To assemble a component 110 in a system, thecomponent 110 must have input and output connections. Thus, a component110 is a unit of abstraction with connection ports 112, 114.

A component 110 in accordance with the present invention employs typedports for plumbing. Components 110 interact with other components 110only via their input and output ports 112, 114. Types are used as aplumbing mechanism to connect components together. An output port 114 ofone component 110-a can only be connected to a conforming input port 112of another component 110-b. Typing essentially restricts the kinds ofmessages (i.e., operations) that can be passed from one component 110-ato another component 110-b.

The software programming environment of the present invention providestemplates that allow the various contracts of components 110 in thesystem and how components interact with one another to be specified at avery high level. Templates give signatures to components 110.

Components 110 in accordance with the present invention and interactionsbetween components 110 are loosely coupled. Ideally, one component 110-ashould not be aware of the identity of other components 110 in thesystem. Loose coupling enhances maintainability and reusability ofcomponents. Implicit invocation is an architectural style for achievingsuch loose coupling among components.

There is no inheritance mechanism between components 110. Components 110are individual off-the-shelf units. One component 110 cannot inheritanother component's 110 internal structure and behavior. A component 110itself is made of some internal structures that are not observablebeyond the component 110. These internal structures can have inheritancerelations among themselves. One can think of a component to be made of aset of related classes that implement the logic of the component, in asimilar manner to Design Patterns.

Components 110 in the software programming environment of the presentinvention do not have global states (such as global variables, publicclasses, and public methods) that are visible throughout the system.Global states inhibit reuse and maintenance of software components.

The only interaction that a component 110 has with the external world isthrough its input/output ports 112, 114. The specification or thecontract of a component 110, such as the input and output behavior,invariance, and dependencies to other components 110 should be clearlyspecified. For example, for a File Transfer Protocol (FTP) component110, it is important that a client first “connects” to a file serverbefore issuing a get file command.

Defining and Creating Components

Interfaces

Interfaces are a set of named operations and defined constants. In thepresent programming environment, interfaces are used to type ports 112,114 in a template, and also to type method parameters and return values.The present programming environment supports multiple inheritance amonginterfaces. Interface inheritance establishes a subtype relation amonginterfaces. If a first, interface, I, extends a second interface, J,then I is called the subtype of J, and is denoted as I <: J. If I <: J,then I can be substituted in place of J. The subtype relation in thepresent programming environment forms a directed acyclic graphstructure, where nodes are interfaces and edges correspond to thesubtype relation.

Templates

A template is a signature to components 110. A template consists of aset of declarations for constructors, input ports 112, and output ports114. A template may be implemented by one or more components 110. Boththe input ports 112 and the output ports 114 are typed. These ports 112,114 act as connectors when component instances are connected or plumbedtogether. The port names within a template should be distinct, andmultiple ports can have the same type.

In the present environment, one template can extend other templates,forming a template inheritance hierarchy. Once again, the templateinheritance hierarchy forms a directed acyclic graph (dag) structure.Let T and S be two templates, such that T extends S. Then T is called asub-template of S, and is denoted as T<<S. One can substitute T where Sis expected. If T extends S, then T inherits all the constructors, inputports 112, and output ports 114. T can also define its own constructorsand ports.

A sub-template can redefine the type of a port 112, 114. Let a templateT extend another template S, and let Ti and To be the types of an inputport 112 and an output port 114 of T, respectively. Also, let Si and Sobe the types of the corresponding input port 112 and the output port 114in S, respectively (i.e., the port names are the same in bothtemplates). Then, for the override to be safe, Ti<: Si, and So<: To. Inthe present environment, templates are passed as parameters to methodsand template values are returned.

In the present environment, template constructors are used forsupporting implicit invocation and multicasting, as discussed below in asection entitled “Implicit Invocation and Multitasking.” A signature ofa constructor consists of the number of parameters, and the type of eachparameter. Constructors do not have a return type. A template caninherit a constructor declaration from its ancestor template. Theinherited constructor in a template T gets the same name as T. Let atemplate T extend another template S, and Ct and Cs be constructorsdeclared in the two templates, respectively. Ct and Cs are said to beequivalent if and only if they have the same number of parameters andthe type of each parameter is also the same. Also, Ct is said tooverride Cs. The name of a constructor does not affect the equivalencerelation.

Groups

A related set of templates can be grouped together to form a group. Forinstance,

group MyGroup { T1, T2, . . . , Tn}

forms a new group with MyGroup as its group name and templates T1 to Tnas its members. As discussed further below in a section entitled“Implicit Invocation and Multitasking,” groups are useful forimplementing implicit invocation. A component can register or subscribeto a group. A client can publish content to a group and all theregistered components will receive the published content from the group.

Components

A component 110 is a unit of computation. A component definitionconsists of two portions: an external portion and an internal portion.The external portion consists of a set of input ports 112, output ports114, and constructors. A component 110 may implement a templatestructure, in which case it should implement all the input ports 112 andconstructors defined in the template. A port (constructor) in acomponent 110 can override a port (constructor) declared in a template,and the overriding rule is exactly the same as for the template overridedefined above. There is no inheritance relation among components 110.Each input port 112 in a component 110 should be attached (using theattach command) to some concrete class with in the component 110. Thisclass should implement the type of the input port 112. The “attached”class acts as a proxy to the information arriving at that input port112. An input port 112 can be attached to more than one class. In thiscase, when information arrives at the input port 112, the information isforwarded to all the attached classes, in a similar manner tomulticasting.

In the programming environment of the present invention, new instancesof a component 110 are created using the “new” command. For example, thestatement MyComponent myComp=new MyComponent( ) creates an instance ofthe component 110 by invoking the constructor MyComponent( ). Thekeyword “This” is used as the reference to the current componentinstance. As used herein, the term “one component interacts with anothercomponent,” generally means component instances. In other words, acomponent instance must first be created before methods at the outputport can be connected and invoked. But, sometimes we need the ability toinvoke certain operations even prior to creating component instances,such as the ability to initialize a component 110. A component 110 canhave a special initialization function, init( ), that that can bedirectly called by the client component without instantiating acomponent instance. An init( ) function can take a set of typedparameters and can return a typed value.

Members in a component 110 may be declared as static, in which case themembers are common to all instances of a component 110. The method main() is a special static method that only a virtual machine (VM) or aruntime system can use as an entry point to the application. Eachcomponent instance may have its own instance fields. A component 110 candefine private interfaces that the classes within the component 110 canimplement. A class may implement only interfaces that are defined at theinput port 112 or the interfaces that are private to the component 110.Private interfaces are useful when components 110 perform complicatedtasks within it.

Classes

Classes and methods in a component 110 implement the logic of thecomponent 110. One can create instances of a class using the “new”operator. We use the keyword “this” as the reference to the currentclass instance. Classes in a component 110 can have only instancemembers, and static declarations are not allowed within a classdefinition. Members of a class can be declared as private. A privatemember is visible only within the class. Once again, there are no publicand protected modifiers in a class.

Classes can use component fields and methods to pass information betweenclasses. The class hierarchy forms a tree-like structure, in a similarmanner to single implementation inheritance. The present invention doesnot allow extension of a class beyond the component boundary. A class ora method in a class can also be declared “abstract.” An abstract methodin a class is implemented by an heir class of the abstract class. Aninput port cannot be attached to an abstract class (since one cannotcreate instances of abstract classes, and ports connect componentinstances).

It is noted that while “this” is used to reference the current classinstance, “This” is used for component instances.

Types

The type system of the present invention consists of primitive types,interface types, component types, template types, class types, and grouptypes. Currently, only port types are restricted to be of interfacetypes. Other entities like component fields, class fields, methodparameters, return values, and variables can be of any type.

Connecting Components

Integration is a process by which multiple components are made tocooperate. The term integration is often variably referred to ascomposition, plumbing, interaction or communication. An integration canbe either loosely coupled, where components have little knowledge aboutthe existence of other components, or tightly coupled, where a componentknows of the existence of other components that the component isinteracting with. Loose coupling helps to reduce the impact on thesystem when components are added, removed or changed. Also, loosecoupling allows much better reuse of components. On the other hand,tight coupling helps in improving the overall performance of the system.The present invention supports both loose coupling and tightly couplingof components.

A component 110-a that wants to interact with another component 110-bshould first create an instance of that component 110-b. Consider thecomponent, ClientC, discussed in the illustrative example above. In themain( ) program, we first created an instance of the BooleanCompcomponent, and then we connected the output port 114 of an instance ofthe ClientC component 110 to the input port 112 of the BooleanCompcomponent 110. In this case, the client is aware of the existence of theBooleanComp component. The connect statement establishes an explicitconnection between the two components. When we invoke CC.xout.not( ),the client component ClientC knows the component with which it isinteracting. Notice that ClientC is still not aware of whichimplementation within BooleanComp will satisfy the call request.

According to another feature of the invention, an output port 114 of onecomponent 110 can be connected to an input port 112 of another component110 only if they have compatible types. Let CC.xout be an output port114 of a component CC and BC.xin be the input port 112 of anothercomponent BC. For the statement “connect CC.xout to BC.xin” to be safe,the interface type S of BC.xin must be a subtype of the interface type Tof CC.xout. This is because any operation that the component CC requestsvia its xout port 114 should be supported by the component BC at its xinport 112. An output port 114 of a component 110 can be connected to aninput port 112 of more than one component 110. This multiplesimultaneous connection can be used to implement multicasting and designpatterns like the Observer pattern, as discussed in the followingsection.

Implicit Invocation and Multicasting

Ideally, one component 110-a should not be aware of the identity ofother components 110 in a software system. The interaction betweencomponents 110 should be completely decoupled. Decoupling componentinteractions significantly improves maintainability, adaptability, andreusability of components. The interaction between decoupled componentsis referred to as implicit invocation. Observer pattern, event-drivenmechanism, selective broadcasting, publish-subscribe model, andmulticasting are some of the designs that support some form of implicitinvocation.

Implicit invocation is a software architecture style that allowssoftware components to announce interesting events, which in turn, causethe actual invocation to happen on all those components that haveregistered interests in the events. In implicit invocation, an eventannouncer is decoupled from the event recipients. Usually a centralmechanism manages the dependencies between the announcer and therecipients. Possible applications of implicit invocation includereal-time data distribution (such as weather report, stock reports, andsports score report), file distributions for software updates, and emailgroups.

For example, an Observer pattern implements a way to capture one-to-manydependencies between objects so that when one object changes state, allits dependent objects are notified and updated automatically. AnObserver pattern consists of two kinds of players: (1) the subject thatpublishes the change, and (2) a set of observers that wants to observethe change. Assume that you subscribe to a stock-tip mailing group, andwithin this group certain members (i.e., the observers) are interestedonly in certain kind of stock sectors. A stock-tip publisher publishesstock tips on different sectors to the group. The system willselectively send only those stock tips to the sectors that the membersselected. To implement the Observer pattern, a group is initiallycreated using the group construct. A group consists of a set oftemplates, and these templates act as filters to messages sent to thegroup. A group acts as a mediator between the publisher and thesubscribers. The interface hierarchy for stock tips is defined asfollows:

interface StockTipI { generalTip(String s);//general tips } interfaceFinStockTipI extends StockTipI { finTip(String s);//financial stock tips} interface TechStockTipI extends StockTipI { techTip(String s);//techstock tips. }

Next, the templates for stock components are defined as follows:

template StockT { StockT( );//constructor declaration in StockTipI sin;} template FinStockT extends StockT { FinStockT( );//constructor inFinStockTipI sin; } template TechStockT extends StockT { TechStockT();//constructor in TechStockTipI sin; }

In the above template hierarchy, FinStockT and TechStockT aresub-templates of StockT. The constructors FinStockT( ) and TechStockTboth override the constructor StockT( ), for reasons described above inthe sub-section entitled “Templates.”

A group, referred to as StockGroup, is then created that consists oftemplate members, as follows:

group StockGroup { StockT, FinStockT, TechStockT}

Groups are needed for achieving multicasting (e.g., where a message canbe posted for a group and the message is automatically distributed toeach member of the group). Components can register to a group to receivemessages that are posted to the group. Templates in the group act asfilters to messages sent to the group.

Stock components are then implemented using the templates defined above.These components act as observers for the stock tips.

component FinStockC implements FinStockT { attach sin toStockTipClass;//attach the input port FinStockC( ) {...};//componentconstructor implementation class FinStockTipClass implementsFinStockTipI { FinStockTipClass( ) {...}//class constructor voidgeneralTip(String s) {//implement general tip method println(“GeneralTip”+s); } void finTip( ) {//implement financial tip println(“FinanceStock Tip”+s); } } } component TechStockC implements TechStockT { attachsin to StockTipClass;//attach the input port TechStockC( ){...};//component constructor implementation class TechStockTipClassimplements TechStockTipI { TechStockTipClass( ) {...}//class constructorvoid generalTip(String s) {//implement general tip methodprintln(“General Tip”+s); } void techTip(String s) {//implement tech tipprintln(“Tech Stock Tip”+s); } }

To receive information from the group StockGroup, the recipients shouldfirst register with the group, in the following exemplary manner thatuses a property file (written in XML format):

<component name = “FinStockC”> <register-with name = “StockGroup”\><\component> <component name = “TechStockC”> <register-with name =“StockGroup”\> <\component>

An implementation of a subject that publishes stock tips is defined asfollows:

component StockPublisher { out FinStockTipI finout;//publish financestock out TechStockTipI techout;//publish tech stock StockPublisher( ){...}//constructor static void main( ) { FinStockT FT = newStockGroup.FinStockT( )//create observer instances StockPublisher SP =new StockPublisher( )//create subject instance connect SP.finout toFT.sin;//connect the publisher to subscriberSC.finout.generalTip(“Market is good!”);//invoke the interface operationSC.finout.finTip(“Buy!”); }

The constructor declarations FinStockT( ) and StockT( ) are equivalent,and the component FinStockC implements one constructor FinStockC( ) thatis a representative for both the template constructors (similarly forthe tech stock constructors).

The group StockGroup consists of three templates. These templates act asfilters when messages are posted to StockGroup. Notice that both theobserver components FinStockC and TechStockC are registered with thegroup StockGroup.

The key to multicasting and filtering is the statement:

FinStockT FT=new StockGroup.FinStockT( )

Here we apply the “new” operation to a template member FinStockT of theStockGroup. The new statement creates component instances of allcomponents that are registered with StockGroup and have implemented theFinStockT template. In our case, although both FinStockC and TechStockCcomponents have registered with StockGroup, only FinStockC componentimplements FinStockT template. Therefore, the new statement creates aninstance of only FinStockC component (and no instance for TechStock iscreated).

The statement connect “SP.finout to FT.sin” connects the componentinstance of StackPublisher to component instances pointed to FT, whichhere is the component FinStockC.

The two method invocations “SC.finout.generalTip(“Market is good!”)” and“SC.finout.finTip(“Buy!”)” once again invoke only methods defined in theFinStockC component.

It is noted that a single call statement such asSC.finout.finTip(“Buy!”) may invoke methods in more than one component.It is further noted that the subject component is not even aware of theobserver components that participate. Typically, in object orientedimplementations of the Observer pattern, the subject gets a handle toinstances of the observer (this is because, the observer has to firstregister with the subject that it is interested in the finTip( ) event).

Generic Types

Generic types allow one to define a “general” type that can beinstantiated to more a specific type. Generic types are useful to definecollection components. Generic components consist of a port whose typeis a generic type. Genericity is based on F-bounded parametricgenericity. A generic stack component is constructed as follows. First,StackInterface is defined as follows:

interface StackInterface<A> { A pop( ); push(A e); } Next we defineStackTemplate: template StackTemplate { in StackInterface <A> xin; }

Finally, we define a generic stack component:

template StackComponent { attach xin to StackClass; StackComponent( );class StackClass <A> implements StackInterface <A>{ push(A) {...} A pop() {...} } }

The client code for accessing the StackComponent follows:

template ClientTemplate { out StackInterface<int> xoutInt; outStackInterface<char> xoutChar; }

The client component that implements the above template is as follows:

component ClientComponent { static main( ) { StackComponent sc = newStackComponent( );//create an instance ClientComponent cc = newClientComponent( );//create client instance connect cc.xoutInt tosc.xin<int>;//connect the two cc.xoutInt.push(10);//use the stackcomponent. int x = cc.xoutInt.pop( ); connect cc.xoutChar tosc.xin<char>; xoutChar.push(char); } }

The above client code creates one instance of StackComponent andconnects the two output ports of ClientComponent to the same input portof StackComponent. It is noted that the actual type of the port ispassed only when the two components are connected together.

Higher-Order Component Programming

In the world of component-based software, a set of components interactwith each other in a container. The container essentially providesservices such as security, transaction coordination, and life-cyclemanagement. A client that wants to access the services of a componenthas to go through the container. The present invention can model acontainer as a component, except that some of the ports are typed usingcontracts. The following example illustrates higher-order componentprogramming:

interface BooleanI { boolean not (boolean b); } component Container { inBooleanCont bci; attach bci to BooleanComp; component BooleanCompimplements BooleanCont { attach bi to BooleanCls; class BooleanClsimplements BooleanI { boolean not(boolean x){ return {tilde over ( )}x;} } } } contract BooleanCont { in BooleanI bi; } component ClientBool {out BooleanCont bco; out BooleanI bio; ... class MainI implements Main{void main( ) { Container c = new Container( ); connect bco to c.in;connect bio to bco.bin; boolean x = bio.not(true); } } }

The input port bci of the Container component is a contract. The portbci is attached to the component BooleanComp that implements thecontract type BooleanCont. The client component first creates aninstance of the Container component, and connects to it via bcout port.It then connects the bio to bcout.bin. Finally, it invokes the bio.not() service. It is noted that the client component is once again unawareof the component within Container that implements the contractBooleanCont.

Delegates

It may be useful to export a component instance method (rather than aclass instance method). As previously indicated, however, one of thefeatures of the present invention is that clients can only communicatewith a component by means of its input/output ports. One possiblesolution is to encapsulate a component instance method in a class andthen provide an interface that hooks up a class (that implements theinterface) to an input port. Another solution is to use delegates totype ports. Delegates are like function pointers, except that it issecure, type-safe, and encapsulated. A delegate is a type which can beattached to a concrete method (just as an interface is a type that canbe attached to a concrete class). In other words, a delegate is a typefor defining a method signature, so that delegate instances can hold andinvoke a method that matches its signature. The following exampleillustrates the use of delegates:

delegate Boolean FilterD (string s); component FilterComp{ in FilterDfin; attach xin to FilterMethod; boolean FilterMethod (string s) {...} }component ClientComp { out FilterD fout; ... void main ( ) { FilterCompsc = new FilterComp ( ); connect fout to sc.fin; //invoke the delegatevia fout. boolean flag = fout (“blah...blah”); } }

It is noted that the output port fout is connected to the input portfin, and since fout is of delegate type the service is invoked as fout(. . . ).

FIG. 2 is a block diagram showing the architecture of an illustrativesoftware component programming system 200. The software componentprogramming system 200 may be embodied, for example, as a workstation,personal computer or other computing device, as modified herein toexecute the functions and operations of the present invention. Thesoftware component programming system 200 includes a processor 210 andrelated memory, such as a data storage device 220. The processor 210 maybe embodied as a single processor, or a number of processors operatingin parallel. The data storage device 220 and/or a read only memory (ROM)are operable to store one or more instructions, which the processor 210is operable to retrieve, interpret and execute.

The data storage device 220 includes operating system program code 250,such as an exemplary Linux, Unix or Windows operating system. The datastorage device 220 also includes the software component programminglanguage 260, incorporating features of the present invention, that maybe used to generate application code 270. The communications port 220optionally connects the software component programming system 200 to anetwork environment (not shown).

FIG. 3 defines the syntax used by the present invention. ƒ* means zeroor more occurences of f, [t ƒ]* means t₁ f₁, . . . t_(n) f_(n), andthis.ƒ* means this.f₁ . . . this.f_(n). The underlined parts shown inFIG. 3 are the context introduced by type elaboration.

FIG. 4 outlines the identifiers used by the present invention. It isassumed that names for variables, components, contracts, interfaces,classes, fields and methods are distinct.

It is to be understood that the embodiments and variations shown anddescribed herein are merely illustrative of the principles of thisinvention and that various modifications may be implemented by thoseskilled in the art without departing from the scope and spirit of theinvention.

1. A method executed by a processor for programming a softwarecomponent, said method comprising the steps of: defining properties ofsaid software component, including at least one input port and at leastone output port; providing a software mechanism for instantiating saidsoftware component; and utilizing an attach command to attach at leastone of said at least one input port to a class.
 2. A system forprogramming a software component, said system comprising: a memory thatstores computer-readable code; and a processor operatively coupled tosaid memory, said processor configured to implement saidcomputer-readable code, said computer-readable code configured to:define properties of said software component, including at least oneinput port and at least one output port; provide a software mechanismfor instantiating said software component; and utilize an attach commandto attach at least one of said at least one input port to a class.
 3. Anarticle of manufacture for programming a software component, said systemcomprising: a computer readable medium having computer readable codemeans embodied thereon, said computer readable program code meanscomprising: a step to define properties of said software component,including at least one input port and at least one output port; a stepto provide a software mechanism for instantiating said softwarecomponent; and a step to utilize an attach command to attach at leastone of said at least one input port to a class.